
//    var root_path = "http://114.215.84.189:8888/exiaodao";
	
	//获取项目根路径
	function getRootPath() {
	    var pathName = window.location.pathname.substring(1);
	    var webName = pathName == '' ? '' : pathName.substring(0, pathName.indexOf('/'));
	    return window.location.protocol + '//' + window.location.host + '/' + webName + '/';
	}

	var root_path = getRootPath();		// 全局根路径
	
    var tipMessage = {
	    error_msg: '服务器异常，稍后重试！',
	    undefined_msg: '数据加载失败，稍后重试！',
	    unlogin_msg: '请先登录！',
	    nogoods_msg: "该商品已下架！"
	}
    //页面跳转
    function RedirectUrl(url) {
        window.location.href = url;
    }

    //获取URL地址参数
    function GetQueryString(name) {
        var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
        var r = window.location.search.substr(1).match(reg);
        if (r != null) return unescape(r[2]);
        return null;
    }
    //显示提示的div
	function showTips(message,url){
		$('.ui-poptips-cnt').html(message);
		$('.ui-poptips').show();
		if(url){
			setTimeout(function(){$('.ui-poptips').hide();RedirectUrl(url)}, 1500);
		}else{
			setTimeout("$('.ui-poptips').hide()", 1500);
		}
	}

    //禁止选中
    document.onselectstart = function () {
        return false;
    }

    //禁止按钮点击效果
	function disabled_btn(obj){
		$(obj).addClass('disable_click');
	}
	//激活按钮点击事件
	function active_btn(obj){
		$(obj).removeClass('disable_click');
	}
    //倒计时效果
	function countDown(obj){
		var _timer = new Date();
		_timer.setTime(_timer.getTime()+5*60*1000); //设置date为当前时间+30分
		document.cookie="key2=1; expires="+_timer.toGMTString(); //将date赋值给expires
		var btn = $(obj);
		var count=60;
		var timer=setInterval(function(){
		    count--;
		    btn.html(count+'s');
		    if(count==0){
		        clearInterval(timer);
		        btn.html("重新获取");
		    }
		},1000);
	}
	/**
	 *	发送验证码
	 *  obj：当前点击事件的按钮，mobile_obj：要验证的手机号对象
	 *  from：来自哪个页面
	 *  forget：是否忘记密码
	 */
		
	function send_code(obj,mobile_obj,_from,type,mobileEncrypt,device){
		if($(obj).html() != '获取验证码' && $(obj).html() != '重新获取'){
		    showTips('请稍后再获取验证码！');
		    return;
		}
		var _info = "手机号";
		if(_from == 2){
			_info = "现手机号";
		}
		if(!$(mobile_obj).val()){
		    showTips('请输入' + _info + '！');
		    return;
		}

        var mobile_reg = new RegExp(/^1[3-9]\d{9}$/);
        if(!mobile_reg.test($(mobile_obj).val())){
		    showTips(_info + '格式不正确！');
		    return;
        }
		if(!$("#code").val()){
			showTips('请输入图形验证码！');
			return;
		}
		disabled_btn(obj);
		$.ajax({
		    url: root_path+"/api/user/sendCode",
		    type: 'post',
		    data: {  
		      	"mobile": $(mobile_obj).val(),
		      	"imgCode": $('#code').val(),
				"imgUrl": root_path+$("#vCode1").find("img").attr("src"),
				"type":type,
				"mobileEncrypt":mobileEncrypt,
				"device":device
		    },
		    success: function(result) {
				console.log($(mobile_obj).val())
				console.log($('#code').val())
				console.log(root_path+$("#vCode1").find("img").attr("src"))
				console.log(type)
				console.log(mobileEncrypt)
				console.log(device)
				console.log(result)
		        active_btn(obj);
		        if(result.code == 1){
		            countDown(obj);
		        }else{
		            showTips(result.message || tipMessage.undefined_msg);
		        }
		    },
		    error: function(){
		        active_btn(obj);
		        showTips(tipMessage.error_msg);
		    }
		});
	}
	function img_code(){
		$.ajax({
			url: root_path + "/api/user/getValiCode",
			type: 'post',
			data: {
			},
			success: function (result) {
				console.log(result)
				if (result.code == 1) {
					$("#vCode1").html("<img src="+root_path+result.object+" />")
				} else {
					showTips(result.message || tipMessage.undefined_msg);
				}
			},
			error: function () {
				showTips(tipMessage.error_msg);
			}
		})
	}


